import request from "@/utils/request";

// 添加组别到部门（批量）
export function addGroupsToDept(deptId: string, groupIds: string[]) {
  return request<boolean>({
    url: `/DeptGroup/${deptId}/groups`,
    method: "POST",
    data: groupIds
  });
}

// 从部门移除组别（批量）
export function removeGroupsFromDept(deptId: string, groupIds: string[]) {
  return request<boolean>({
    url: `/DeptGroup/${deptId}/groups`,
    method: "DELETE",
    data: groupIds
  });
}

// 更新关联状态
export function updateDeptGroupStatus(relationId: string, isActive: string) {
  return request<boolean>({
    url: `/DeptGroup/${relationId}/status`,
    method: "PUT",
    data: { isActive }
  });
}

// 获取部门的关联组别
export function getDeptGroups(deptId: string) {
  return request({
    url: `/DeptGroup/${deptId}/groups`,
    method: "GET",

  });
}

// 获取部门可用的组别
export function getAvailableGroupsForDept(deptId: string) {
  return request({
    url: `/DeptGroup/GetAvailableGroups`,
    method: "GET",
    data: deptId
  });
}

// 删除单个关联
export function deleteDeptGroup(relationId: string) {
  return request<boolean>({
    url: `/DeptGroup/${relationId}`,
    method: "DELETE"
  });
}

// 获取所有部门
export function getAllDepts() {
  return request({
    url: "/Dept/GetAll",
    method: "GET"
  });
}

// 获取所有组别
export function getAllGroups() {
  return request({
    url: "/GroupMaster/GetAll",
    method: "GET"
  });
}

// 类型定义
export interface Dept {
  Id: string;
  Name: string;
}

export interface Group {
  Id: string
  Name: string
  Category: string
}

export interface DeptGroupRelation {
  Id: string
  deptId: string
  groupId: string
  IsActive: string
  CreatedAt: string;
  ModifiedAt: string;
}